<?php

import('@.Model.Extend.AlbumViewModel');
import('@.Model.Where.AlbumWhereMachine');
import('@.Model.Extend.UserMark');
class EventAlbum{
    private $event, $eventMark, $album;
    private $map, $eid, $uid;
    public function EventAlbum($eid, $uid=null){
        $eventM= new UserMark($uid);
        $this->uid= $uid;
        $this->eid= $eid;
        //$this->event= $eventM->find('Event.id='.$this->eid);
        
    }
    public function allowUpload(){
        $e= $this->getEvent();
        if ($e['take'] ==EventMarkModel::C('MARK_TAKE')){
            return true;
        } else if ($e['author_id'] ==$this->uid){
            return true;
        }
        return false;
    }
    public function getAlbum($start=0, $limit=20){
        if (! $this->album){
            $this->map= new AlbumWhereMachine();
            $this->map->type(AlbumModel::C('TYPE_EVENT'))->aid($this->eid)
                ->set('Album.state', AlbumModel::C('STATE_NORMAL'));
            $this->album= $this->getAlbumModel()->limit($start.','.$limit)->select();
        }
        return $this->album;
    }
    public function getAlbumCount(){
        return $this->getAlbumModel()->count();
    }
    protected function getAlbumModel(){
        $this->map= new AlbumWhereMachine();
        $this->map->type(AlbumModel::C('TYPE_EVENT'))->aid($this->eid)
            ->set('Album.state', AlbumModel::C('STATE_NORMAL'));
        $albumM= new AlbumViewModel();
        return $albumM->where($this->map->get())->order('id DESC');
    }
    public function getEvent(){
        if (! $this->event){
            $this->event= M('Event')->field(array('id', 'title', 'img', 'visibility'))->find($this->eid);
        }
        return $this->event;
    }
    public function getEventMark(){
        if (! $this->eventMark){
            $map=array(
                'uid'=>$this->uid,
                'eid'=>$this->eid,
            );
            $this->eventMark=M('EventMark')->where($map)->find();
        }
        return $this->eventMark;
    }
}

?>